﻿using LivestreamE_Commerce.Dto.AllDto;
using LivestreamE_Commerce.Dto.CreateUpdateDto;
using LivestreamE_Commerce.Dto.RBACDto;
using LivestreamE_Commerce.Dto.Tree;
using LivestreamE_Commerce.EntityFrameworkCore;
using LivestreamE_Commerce.IService.RBACIService;
using LivestreamE_Commerce.Model.RBAC;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace LivestreamE_Commerce.Service.RBACService
{
    public class MyRoleService : CrudAppService<RoleModel, RoleDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateRoleDto>, IMyRoleService
    {
        LivestreamE_CommerceDbContext db;
        public MyRoleService(IRepository<RoleModel, Guid> repository, LivestreamE_CommerceDbContext _db) : base(repository)
        {
            db = _db;
        }
        [HttpGet]
        public IEnumerable<UserRoleAllDto> UserPermissionDisplay()
        {
            var list = (from a in db.UserModel
                        join b in db.UserRoleFinder
                        on a.Id equals b.UserId
                        join c in db.RoleModel
                        on b.RoleId equals c.Id
                        join d in db.RoleMenuModel
                        on c.Id equals d.RoleId
                        join e in db.MenuModel
                        on d.MenuId equals e.Id
                        select new UserRoleAllDto
                        {
                            UserName = a.UserName,
                            RoleName = c.RoleName,
                        }).ToList();
            return list;
        }

    }
}
